package com.darrenchan.leetcode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @Desc 数据流中的移动平均值
 * @Author chenchi03
 * @CreateTime 2019-12-22 21:01
 */
public class Q346 {
    private Queue<Integer> queue;
    private int size;
    private int sum = 0;

    public Q346(int size) {
        this.queue = new LinkedList<>();
        this.size = size;
    }

    private double getNext(int val) {
        queue.add(val);
        sum += val;
        if(queue.size() > size){
            sum -= queue.poll();
        }
        return sum * 1.0 / size;
    }
}
